import {
	getJwt
} from "@/utils/index";
import axios from 'axios'
import store from '@/store/index'
import dayjs from 'dayjs'
import {
	Toast
} from 'vant';
// 创建axios实例
let jwt=getJwt()
const service = axios.create({
	baseURL: myConfig.commonURL,
	timeout: 30000,
	method: 'post',
	headers: {
		'content-type': 'application/json', //默认值
		'Authorization': `Bearer ${jwt}`
	},
})
// request拦截器
service.interceptors.request.use(config => {


	return config
}, error => {
	console.log(error)
	Promise.reject(error)
})

// 响应拦截器
service.interceptors.response.use(res => {
		let result = res.data;
		if (result.RESULTCODE == 0) {
			result = {
				success: true,
				data: result.Body
			}
		} else {
			result = {
				success: false,
				data: {},
				msg: result.RESULTCONTENT,
			}
			Toast({
				message: result.msg+'入参：'+JSON.stringify(res.config.params) || '业务出错',
			});
		}

		return result;

	},
	error => {
		if (error.status == '401') {
			//token过期
			console.log('token过期',error.status)
		} else {

		}
		Toast({
			message: error.message || '服务出错',

		});
		return error
	}
)
export default service